package enumdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张杰
 * Date: 2022-03-17
 * Time: 11:50
 */
public enum TestEnum {
    //枚举是不能继承的
    RED("red",1),BLACK("black",3),GREEN("green",8);

    public String color;
    public int ordinal;
    TestEnum(String color,int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }
    //默认构造方法是枚举的
    /*private TestEnum() {

    }*/

    public static void main(String[] args) {
        //把字符串 变成对应的枚举对象
        TestEnum testEnum = TestEnum.valueOf("RED");
        System.out.println(testEnum);

        //默认索引进行比较
        System.out.println(RED.compareTo(GREEN));

        System.out.println(BLACK.compareTo(RED));
    }
    public static void main2(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length ; i++) {
            System.out.println(testEnums[i]+"->"+testEnums[i].ordinal());
        }
    }
    public static void main1(String[] args) {
        TestEnum testEnum2 = TestEnum.BLACK;
        switch (testEnum2) {
            case RED:
                System.out.println("red");
                break;
            case BLACK:
                System.out.println("black");
                break;
            case GREEN:
                System.out.println("green");
        }
    }
}
